<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Spreaduser extends CI_Controller {
	
	public function __construct(){
		
		parent::__construct();
	}
	
	public function isactive(){
		 
		$mid = $this->uri->segment(3);
		$isactive = $this->input->post('audit');
		$reason = $this->input->post('reason');
		$q = $this->db->update('sdk_spread_user',array('isactive'=>$isactive,'reason'=>$reason),array('mid'=>$mid));
		if($q){
			echo "<script>alert('edit success!');window.location='".$_SERVER['HTTP_REFERER']."';</script>";
		}else{
			echo "<script>alert('edit fail!');window.location='".$_SERVER['HTTP_REFERER']."';</script>";
		}
	}
	
	public function percentage(){
		
		$percentage = $this->input->post('percentage');
		$mid = $this->input->post('mid');
		$siteid = $this->input->post('siteid');

		$q = $this->db->get_where('sdk_percentage',array('mid'=>$mid,'siteid'=>$siteid));
		if($q->num_rows>0){
			$q = $this->db->update('sdk_percentage',array('percentage'=>$percentage),array('mid'=>$mid,'siteid'=>$siteid));
			echo  $this->db->affected_rows()>0?"<script>alert('update success!');document.location='".$_SERVER['HTTP_REFERER']."';</script>":"<script>alert('update fail!');document.location='".$_SERVER['HTTP_REFERER']."';</script>";
		}else{
			
			$q = $this->db->insert('sdk_percentage',array('mid'=>$mid,'siteid'=>$siteid,'percentage'=>$percentage));
			echo $this->db->affected_rows()>0?"<script>alert('insert success!');document.location='".$_SERVER['HTTP_REFERER']."';</script>":"<script>alert('insert fail!');document.location='".$_SERVER['HTTP_REFERER']."';</script>";;
		}
		
		
	}
	
	public function dowithdrawal(){
		
		$id = $this->uri->segment(3);
		
		$this->db->update('sdk_extract',array('status'=>1),array('id'=>$id));
		
		if($this->db->affected_rows()>0){
			
			echo "<script>alert('change success!');document.location='".$_SERVER['HTTP_REFERER']."';</script>";
			exit;
		}else{
			
			echo "<script>alert('change fail!');document.location='".$_SERVER['HTTP_REFERER']."';</script>";
			exit;
		}
		
	}
	
	public function tgwz(){
		
		$mid = $this->input->post('mid');
		$siteids = $this->input->post('siteids');
		
		$this->load->model('spreaduser_model','sm');
		$re = 1;
		foreach ($siteids as $k=>$v){
			if(!$this->sm->insert_tgwz($mid,$v)){
				$re = 0;
			}
		}
		if($re==1){
			echo "<script>alert('change success!');document.location='".$_SERVER['HTTP_REFERER']."';</script>";
			exit;
		}else{
			echo "<script>alert('change fail!');document.location='".$_SERVER['HTTP_REFERER']."';</script>";
			exit;
		}
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}